﻿@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
    Layout = null;
}
<link href="~/lib/layui/css/layui.css" rel="stylesheet" />
<script src="~/lib/layui/layui.js"></script>
<script src="~/js/js.cookie.js"></script>
<script src="~/js/moment.js"></script>
<script src="~/lib/jquery/dist/jquery.js"></script>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Demo</title>
</head>
<body class="layui-padding-3">
    <h3 style="color: #34c38f">
        <i class="layui-icon layui-icon-left" style="color: #dcccc0"></i><a style="color: #dcccc0;cursor:pointer" onclick="location.href='/Outbound/OutboundSearch'"> 返回&nbsp;&nbsp;</a><span style="color: #000">|</span>&nbsp;&nbsp;出库单头信息&nbsp;(<i class="layui-icon layui-icon-backspace"></i>)
    </h3>
    <hr style="color: #34c38f" />
    <form class="layui-form" action="">
        <div class="layui-col-md4">
            <div class="layui-form-item">
                <label class="layui-form-label">出库单编码</label>
                <div class="layui-input-block">
                    <input type="text" name="outboundCode" id="outboundCode" placeholder="请输入" class="layui-input" lay-affix="clear">
                </div>
            </div>
        </div>

        <div class="layui-col-md4">
            <div class="layui-form-item">
                <label class="layui-form-label">出货类型</label>
                <div class="layui-input-inline">
                    <select name="outboundTypeId" id="outboundTypeId" lay-verify="required">
                        <option value="2" selected>杂项出库</option>
                    </select>
                </div>
            </div>
        </div>
        <hr />

        <div class="layui-col-md4">
            <div class="layui-form-item">
                <label class="layui-form-label">仓库</label>
                <div class="layui-input-inline">
                    <select name="warehouseId" id="warehouseId" lay-verify="required" lay-search lay-filter="demoselect">
                    </select>
                </div>
            </div>
        </div>
        <div class="layui-col-md4">
            <div class="layui-form-item">
                <label class="layui-form-label">仓库地址</label>
                <div class="layui-input-block">
                    <input type="text" name="warehouseAddr" id="warehouseAddr" placeholder="请输入" class="layui-input" lay-affix="clear">
                </div>
            </div>
        </div>
        <hr />

        <div class="layui-col-md4">
            <div class="layui-form-item">
                <label class="layui-form-label">备注</label>
                <div class="layui-input-block">
                    <input type="text" name="outboundDec" id="outboundDec" placeholder="请输入" class="layui-input" lay-affix="clear">
                </div>
            </div>
        </div>
        <div class="layui-col-md4">
            <div class="layui-form-item">
                <label class="layui-form-label">状态</label>
                <div class="layui-input-block">
                    <input type="text" name="isStatus" id="isStatus" value="新建" placeholder="请输入" class="layui-input" lay-affix="clear">
                </div>
            </div>
        </div>
        <hr />

        <div class="layui-col-md4">
            <div class="layui-form-item">
                <label class="layui-form-label">出库来源</label>
                <div class="layui-input-inline">
                    <select lay-verify="required" lay-search>
                        <option value="1" selected>销售订单</option>
                    </select>
                </div>
            </div>
        </div>
        <div class="layui-col-md4">
            <div class="layui-form-item">
                <label class="layui-form-label">来源编码</label>
                <div class="layui-input-inline">
                    <select name="salesNo" id="salesNo" lay-verify="required" lay-search lay-filter="demo1select">
                    </select>
                </div>
            </div>
        </div>
        <hr />
        <div class="layui-col-md4">
            <div class="layui-form-item">
                <label class="layui-form-label">来源名称</label>
                <div class="layui-input-block">
                    <input type="text" name="salesName" id="salesName" placeholder="请输入" class="layui-input" lay-affix="clear">
                </div>
            </div>
        </div>
        <hr />

        <div class="layui-col-md4">
            <div class="layui-form-item">
                <label class="layui-form-label">客户</label>
                <div class="layui-input-block">
                    <input type="text" name="salesPro" id="salesPro" placeholder="请输入" class="layui-input" lay-affix="clear">
                </div>
            </div>
        </div>
        <div class="layui-col-md4">
            <div class="layui-form-item">
                <label class="layui-form-label">客户联系人</label>
                <div class="layui-input-block">
                    <input type="text" name="salesPro" id="salesPro" placeholder="请输入" class="layui-input" lay-affix="clear">
                </div>
            </div>
        </div>
        <hr />

        <div class="layui-col-md4">
            <div class="layui-form-item">
                <label class="layui-form-label">出库日期</label>
                <div class="layui-input-inline layui-input-wrap">
                    <div class="layui-input-prefix">
                        <i class="layui-icon layui-icon-date"></i>
                    </div>
                    <input type="text" name="outboundDate" id="date" lay-verify="date" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-col-md4">
            <div class="layui-form-item">
                <label class="layui-form-label">出库状态</label>
                <div class="layui-input-block">
                    <input type="text" name="outboundStatus" id="outboundStatus" placeholder="请输入" class="layui-input" lay-affix="clear">
                </div>
            </div>
        </div>
        <hr />


        <div class="layui-col-md6">
            <div class="layui-form-item">
                <label class="layui-form-label">制单人</label>
                <div class="layui-input-block">
                    <input type="text" name="singleMaker" id="singleMaker" readonly value="hhx123" placeholder="请输入" class="layui-input" lay-affix="clear">
                </div>
            </div>
        </div>
        <div class="layui-col-md6">
            <div class="layui-form-item">
                <label class="layui-form-label">制单部门</label>
                <div class="layui-input-inline">
                    <select name="departmentId" id="departmentId" lay-verify="required">
                        <option value="1" selected>仓储部</option>
                    </select>
                </div>
            </div>
        </div>
        <hr />

        <br />
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="submit" id="component" class="layui-btn" lay-submit lay-filter="demo-val">
                    保存
                    <i class="layui-icon layui-icon-right"></i>
                </button>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <!-- 初始显示保存和提交按钮 -->
                <button type="submit" id="saveButton" class="layui-btn layui-icon layui-icon-add-1" lay-submit lay-filter="demo-val">保存</button>
                <button type="button" id="approveButton" class="layui-btn layui-bg-blue" lay-submit lay-filter="demo1-val" onclick="updateState(2)">提交</button>
                <!-- 审核通过按钮和驳回按钮初始隐藏 -->
                <button type="button" id="tongButton" class="layui-btn layui-bg-orange" style="display: none;" lay-submit lay-filter="demo1-val" onclick="updateState(3)">审核通过</button>
                <button type="button" id="boButton" class="layui-btn layui-bg-red" style="display: none;" lay-submit lay-filter="demo1-val" onclick="updateState(4)">驳回</button>
                <button type="button" id="bianButton" class="layui-btn layui-bg-red" style="display: none;" lay-submit lay-filter="demo1-val" onclick="updateState(5)">变更</button>
                <button style="margin-left: 1000px" type="submit" class="layui-btn layui-bg-blue" lay-submit lay-filter="search">
                    提交<i class="layui-icon layui-icon-right"></i>
                </button>
            </div>
        </div>
    </form>

    <h3 style="color: #50a5f1">出库单行信息</h3>
    <hr style="color: #50a5f1" />
    <div class="layui-tab" lay-filter="test-hash">
        <ul class="layui-tab-title">
            <li class="layui-this" lay-id="11">行列表</li>
        </ul>
        <div class="layui-tab-content">
            <div class="layui-tab-item layui-show">
                <table class="layui-hide" id="ID-table-demo-search"></table>
            </div>
        </div>
    </div>

    <script>

        layui.use(['form', 'laydate', 'util','table'], function () {
            var form = layui.form;
            var layer = layui.layer;
            var laydate = layui.laydate;
            var util = layui.util;
            var table = layui.table;
            SearchOutboundType()//出库类型
            SearchWarehouse()//仓库信息
            SearchSales()//销售信息
            // 日期
            laydate.render({
                elem: '#date'
            });
            //物料管理添加
            // 表单取值
            layui.$('#component').on('click', function () {
                var data = form.val('demo-val-filter');
            });
            // 添加提交事件
            form.on('submit(demo-val)', function (data) {
                var field = data.field; // 获取表单字段值;
                var username=localStorage.getItem('userName');
                console.log(username);
                field.createdOwner = username;
                field.createdTime = "" || new Date().toISOString();
                field.updateOwner = "" || null;
                field.updateTime = "" || new Date().toISOString();
                field.examineOwner = "" || null;
                field.examineTime = "" || new Date().toISOString();
                field.isStatus = 1;
                field.isDel = 1;
                field.auditStatus=1;
                field.singleMaker = username;
                field.departmentId=1;
                field.outboundStatus=1;
                console.log(field) //在控制台显示值
                // 此处可执行 Ajax 等操作
                $.ajax({
                    type: "post",
                    url: '@ViewBag.RedDragonWrite'+"/api/OutboundOrders/CreateOutbound",
                    data: JSON.stringify(field),
                    dataType: "json",
                    contentType: "application/json",
                    success: res => {
                        console.log(res)
                        // 处理响应，例如提示成功信息
                        layui.layer.msg(res.msg ,{ icon: 6, time: 1000 });
                        Seach()//物料需求计划
                        Seach1()//工序计划列表
                    },
                    error: function (xhr, status, error) {
                        // 处理错误
                        layui.layer.msg('添加失败', { icon: 5, time: 1000 });
                    }
                })
                return false; // 阻止默认 form 跳转
            });
            //出库类型下拉框绑定
            function SearchOutboundType() {
                $.ajax({
                    url: '@ViewBag.RedDragonWrite' + "/api/OutboundOrders/SearchOutboundType",
                    type: 'GET',
                    dataType: 'json',
                    success: res => {
                        console.log(res)
                        var options = '<option value="0">请选择</option>';
                        $.each(res.data, function (index, item) {
                            options += '<option value="' + item.outboundTypeId + '">' + item.outboundTypeName + '</option>';
                        });
                        $('#outboundTypeId').html(options);
                        form.render('select'); // 更新下拉框渲染
                    }
                });
            }
            //仓库信息选择下拉框绑定
            function SearchWarehouse() {
                $.ajax({
                    url: '@ViewBag.RedDragonWrite' + "/api/OutboundOrders/SearchWarehouse",
                    type: 'GET',
                    dataType: 'json',
                    success: res => {
                        console.log(res)
                        var options = '<option value="0">请选择</option>';
                        $.each(res.data, function (index, item) {
                            options += '<option value="' + item.warehouseId + '">' + item.warehouseName + '</option>';
                        });
                        $('#warehouseId').html(options);
                        form.render('select'); // 更新下拉框渲染
                    }
                });
            }
            //仓库信息下拉框获取值
            form.on('select(demoselect)', function (data) {
                warehouseId = data.value;
                console.log(warehouseId)
                SearchWarehouseID()//仓库信息
            });
            //仓库信息
            function SearchWarehouseID() {
                var warehouseId = $('#warehouseId').val();
                console.log(warehouseId)
                var obj = {
                    warehouseId: warehouseId
                }
                $.ajax({
                    url: '@ViewBag.RedDragonWrite' + "/api/OutboundOrders/SearchWarehouseID",
                    type: 'GET',
                    data: obj,
                    async: false,
                    dataType: 'json',
                    success: res => {
                        console.log(res)
                        $('#warehouseAddr').val(res.data.warehouseAddr);
                    }
                });
            }

             //销售信息选择下拉框绑定
            function SearchSales() {
                $.ajax({
                    url: '@ViewBag.RedDragonWrite' + "/api/OutboundOrders/SearchSales",
                    type: 'get',
                    dataType: 'json',
                    success: res => {
                        console.log(res)
                        var options = '<option value="0">请选择</option>';
                        $.each(res.data, function (index, item) {
                            options += '<option value="' + item.salesNo + '">' + item.salesNo + '</option>';
                        });
                        $('#salesNo').html(options);
                        form.render('select'); // 更新下拉框渲染
                    }
                });
            }

            //销售编号获取销售信息
            form.on('select(demo1select)', function (data) {
                salesNo = data.value;
                console.log(salesNo)
                SearchSalesName()//销售编号获取销售名称
                SearchSalesPro()//获取销售信息客户名称
            });
            //获取销售信息销售名称
            function SearchSalesName() {
                var salesNo = $('#salesNo').val();
                console.log(salesNo)
                var obj = {
                    salesNo: salesNo
                }
                $.ajax({
                    url: '@ViewBag.RedDragonWrite' + "/api/OutboundOrders/SearchSalesId",
                    type: 'GET',
                    data: obj,
                    async: false,
                    dataType: 'json',
                    success: res => {
                        console.log(res)
                        $('#salesName').val(res.data.salesName);
                    }
                });
            }
            //获取销售信息客户名称
            function SearchSalesPro() {
                var salesNo = $('#salesNo').val();
                console.log(salesNo)
                var obj = {
                    salesNo: salesNo
                }
                $.ajax({
                    url: '@ViewBag.RedDragonWrite' + "/api/OutboundOrders/SearchSalesId",
                    type: 'GET',
                    data: obj,
                    async: false,
                    dataType: 'json',
                    success: res => {
                        console.log(res)
                        $('#salesPro').val(res.data.salesPro);
                    }
                });
            }
            // 搜索提交
            function Seach() {
                $.ajax({
                    url:'@ViewBag.RedDragonWrite'+"/api/ProductionTasks/SearchProductionTasks",
                    type: 'get',
                    dataType: "json",
                    contentType: "application/json",
                    success: res => {
                        table.render({
                            elem: '#ID-table-demo-search',
                            cols: [[
                                { field: 'materialId', title: '行号', width: 80 },
                                { field: 'materialId', title: '来源行编码', width: 120 },
                                { field: 'materialCode', title: '物料编码', width: 100 },
                                { field: 'materialName', title: '物料名称', width: 100 },
                                { field: 'specifications', title: '规格类型', width: 100 },
                                { field: 'specifications', title: '单价', width: 100 },
                                { field: 'productionQuantity', title: '成本价', width: 100 },
                                { field: 'productionQuantity', title: '订单数量', width: 100 },
                                { field: 'productionQuantity', title: '单位', width: 100 },
                                { field: 'productionQuantity', title: '金额', width: 100 },
                                { field: 'productionQuantity', title: '退货数量', width: 100 },
                                { field: 'productionQuantity', title: '摘要', width: 100 },
                                {
                                    fixed: 'right',
                                    title: '操作',
                                    width: 134,
                                    minWidth: 125,
                                    templet: '#toolDemo',
                                },
                            ]],
                            data: res.data,
                            page: true,
                            limits: [2, 3, 4],
                            height: 310
                        });
                        return;

                    }
                });
            };
        })
    </script>

    <script type="text/html" id="toolDemo">
        <div class="layui-clear-space">
          <a onclick="" style="color:cornflowerblue;">编辑</a>
          <br />
          <a onclick="" style="color:red">删除</a>
        </div>
    </script>
</body>
</html>